/**
 * @file       Thread.h
 * @brief      TODO
 * @author     Huabo Zheng
 * @date       Jan 19, 2012
 * @Copyright  2012, www.netgear.com Inc. All rights reserved.
 */

#ifndef THREAD_H_
#define THREAD_H_
#include <pthread.h>
#include "typedefine.h"

namespace NS_LCD_AFW
{

/**
 *NS_LCD_AFW::CThread
 */
class CThread
{
public:
	CThread();
	CThread(bool bAutoDelete);
	virtual ~CThread();

	enum EThreadState
	{
		eReady, eRunning, eStop
	};

public:
	bool isAutoDelete();
	int start();
	int join();
	virtual int stop() = 0;
	bool isRunning();
protected:
	void setAutoDelete(bool bAutoDelete);

protected:
	virtual void run() = 0;
	virtual void onException();
	virtual void onExit();
private:
	static void * threadFunc(void * pArg);

private:
	bool m_bAutoDelete;
	volatile EThreadState m_state;
	pthread_t m_tId;

private:
	DISABLE_COPY_CONSTRUCTOR_AND_ASSIGN_REFERENCE(CThread);
};

} /* namespace NS_LCD_AFW */
#endif /* THREAD_H_ */
